package com.weasel.weixin.commons.menu.bean;

import org.codehaus.jackson.annotate.JsonProperty;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Dylan on 2015/10/8.
 */
public class Button {

    private final static int SUB_BUTTON_COUNT = 5;

    @JsonProperty("type")
    private String type;

    @JsonProperty("name")
    private String name;

    @JsonProperty("key")
    private String key;

    @JsonProperty("url")
    private String url;

    @JsonProperty("media_id")
    protected String mediaId;

    @JsonProperty("sub_button")
    protected List<Button> subButton = new ArrayList<>();

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getMediaId() {
        return mediaId;
    }

    public void setMediaId(String mediaId) {
        this.mediaId = mediaId;
    }

    public List<Button> getSubButton() {
        return subButton;
    }

    public void setSubButton(List<Button> subButton) {
        this.subButton = subButton;
    }

    public Button addSubButton(Button _button){

        if(subButton.size() > SUB_BUTTON_COUNT){
            throw new RuntimeException("最多能添加5个二级菜单");
        }
        subButton.add(_button);
        return this;
    }
}
